home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / vmed.arc / VMRIO.CCC < prev    next >
Text File  |  1985-12-03  |  2KB  |  107 lines

  1. /* VMRIO/CCC
  2.  *    virtual memory random I/O asm lang file
  3.  *
  4.  *    Copyright 1983 by Jim Kyle - All Rights Reserved
  5.  *    Licensed for individual non-commercial use only.
  6.  *
  7.  *         created:    November 16, 1983 - Jim Kyle
  8.  *    last changed:    November 23, 1983 - Jim Kyle
  9.  */
  10.  
  11. /*
  12.  *    sec_seek(), fread(), and fwrite() are tailored exact-
  13.  *    ly to LC and the LDOS 5.1.x system (Model 3), and
  14.  *    will require modification to work with other systems.
  15.  *    The sec_seek() function is totally non-K&R; the other
  16.  *    two functions are exactly like the read() and write()
  17.  *    functions described in the K&R book in Chapter
  18.  *    8, except that both use file POINTERS rather than
  19.  *    file DESCRIPTORS to identify the file.
  20.  */
  21.  
  22. sec_seek(fp,sec)    FILE *fp; int sec;    /* sector SEEK */
  23. {
  24. #asm
  25.     $GA    HL,BC        ;recover arg values (LC macro)
  26.     LD    E,(HL)
  27.     INC    HL
  28.     LD    D,(HL)
  29.     INC    DE            ;to FCB itself
  30.     CALL    4442H    ;DOS @POSN routine
  31.     LD    HL,0        ;return OK if no err
  32.     RET    Z
  33.     CP    28            ;end of file?
  34.     RET    Z
  35.     CP    29            ;past end of file?
  36.     RET    Z
  37.     CALL    @ERRET    ;else report error
  38.     LD    HL,-2         ;and return ERR
  39. #endasm
  40. }
  41.  
  42. fread(fp,bfr,n)    FILE *fp; char *bfr; int n;
  43. {
  44. #asm
  45.     $GA    HL,DE,BC    ;get args (LC macro)
  46.     CALL    @GINT    ;get LC FCB adr into HL
  47.     INC    HL            ;to FCB
  48.     EX    DE,HL        ;HL=buf, DE=fcb, BC=n
  49.     INC    BC            ;because of decr in test
  50.     PUSH    BC        ;to stack
  51.     LD    BC,0        ;actual char count
  52.     JR    FREAD3
  53. FREAD1
  54.     EX    (SP),HL
  55.     CALL    0013H    ;DOS @GET routine
  56.     JR    Z,FREAD2
  57.     LD    BC,-1        ;error return value
  58.     JR    FREAD4
  59. FREAD2
  60.     LD    (HL),A
  61.     INC    HL
  62.     INC    BC            ;the count
  63. FREAD3
  64.     EX    (SP),HL        ;swap 'n' and 'buf'
  65.     DEC    HL
  66.     LD    A,H
  67.     OR    L
  68.     JR    NZ,FREAD1    ;not done yet
  69. FREAD4
  70.     POP    HL            ;clean up stack
  71.     LD    H,B
  72.     LD    L,C            ;count of actual transfer
  73. #endasm
  74. }
  75.  
  76. fwrite(fp,bfr,n)    FILE *fp; char *bfr; int n;
  77. {
  78. #asm
  79.     $GA    HL,DE,BC
  80.     CALL    @GINT    ;get LC FCB adr into HL
  81.     INC    HL            ;to true FCB adr
  82.     EX    DE,HL        ;HL=buf, DE=fcb, BC=n
  83.     INC    BC            ;because of decr in test
  84.     PUSH    BC        ;to stack
  85.     LD    BC,0        ;actual char count
  86.     JR    FWRT2
  87. FWRT1
  88.     EX    (SP),HL        ;get buf adr back into HL
  89.     LD    A,(HL)
  90.     INC    HL
  91.     CALL    001BH    ;DOS @PUT routine
  92.     JR    NZ,FWRT3    ;in case of any error
  93.     INC    BC            ;the count
  94. FWRT2
  95.     EX    (SP),HL        ;swap 'n' and 'buf'
  96.     DEC    HL
  97.     LD    A,H
  98.     OR    L
  99.     JR    NZ,FWRT1    ;not done yet
  100. FWRT3
  101.     POP    HL            ;clean up stack
  102.     LD    H,B
  103.     LD    L,C            ;count of actual transfer
  104. #endasm
  105. }
  106.  
  107.